using System;
using System.Web.Core;

namespace Forum.Business
{
    public class RequestHelper
    {
        public static BaseRequestBinder BuildGetUserRequest(BaseUserControl source)
        {
            return new TRequestBinder<ForumUserReply, GetOperation>
            (
                source, RequestBuilder.BuildGetEntityRequest<ForumUserRequest>()
            );
        }
        public static BaseRequestBinder BuildGetUserRequest(int userId)
        {
            return new TBaseRequestBinder<ForumUserReply, GetOperation>
            (
                RequestBuilder.BuildGetEntityRequest<ForumUserRequest>(userId)
            );
        }
        public static BaseRequestBinder BuildGetUserRequest(Guid memberId)
        {
            ForumUserRequest request = new ForumUserRequest();
            request.CommandIdent = CommandIdent.GetUser;
            request.MemberId = memberId;
            request.EntityId = 0;

            BaseRequestBinder binder = new TBaseRequestBinder<ForumUserReply, GetOperation>
            (
                RequestBuilder.BuildGetEntityRequest(request)
            );
            return binder;
        }
        public static BaseRequestBinder BuildGetUserRequest(BaseUserControl source, int userId)
        {
            return new TRequestBinder<ForumUserReply, GetOperation>
            (
                source, RequestBuilder.BuildGetEntityRequest<ForumUserRequest>(userId)
            );
        }
        public static BaseRequestBinder BuildGetUserListRequest(BaseUserControl source, int pageSize)
        {
            ForumUserListRequest request = new ForumUserListRequest();
            request.PageSize = pageSize;

            return new TRequestBinder<ForumUserReply, GetListOperation>
            (
                source, RequestBuilder.BuildGetEntityListRequest(request)
            );
        }
        public static BaseRequestBinder BuildDeleteUserRequest(int userId)
        {
            return new TBaseRequestBinder<ForumUserReply, DeleteOperation>
            (
                RequestBuilder.BuildDeleteEntityRequest<ForumUserRequest>(userId)
            );
        }
        public static BaseRequestBinder BuildUpdateUserRequest(ForumUser user)
        {
            return new TBaseRequestBinder<ForumUserReply, UpdateOperation>
            (
                RequestBuilder.BuildUpdateEntityRequest<ForumUserRequest>(user)
            );
        }

        public static BaseRequestBinder BuildGetGroupRequest(BaseUserControl source)
        {
            return new TRequestBinder<GroupReply, GetOperation>
            (
                source, RequestBuilder.BuildGetEntityRequest<GroupRequest>()
            );
        }
        public static BaseRequestBinder BuildGetGroupRequest(int groupId)
        {
            return new TBaseRequestBinder<GroupReply, GetOperation>
            (
                RequestBuilder.BuildGetEntityRequest<GroupRequest>(groupId)
            );
        }
        public static BaseRequestBinder BuildGetGroupRequest(BaseUserControl source, int groupId)
        {
            return new TRequestBinder<GroupReply, GetOperation>
            (
                source, RequestBuilder.BuildGetEntityRequest<GroupRequest>(groupId)
            );
        }
        public static BaseRequestBinder BuildGetGroupListRequest(BaseUserControl source)
        {
            return new TRequestBinder<GroupReply, GetListOperation>
            (
                source, RequestBuilder.BuildGetEntityListRequest<GroupListRequest>()
            );
        }
        public static BaseRequestBinder BuildGetAllGroupListRequest(BaseUserControl source)
        {
            GroupListRequest request = new GroupListRequest();
            request.PageIndex = 0;
            request.PageSize = 10000;
            return new TRequestBinder<GroupReply, GetListOperation>
            (
                source, RequestBuilder.BuildGetEntityListRequest(request)
            );
        }
        public static BaseRequestBinder BuildGetGroupListRequest(BaseUserControl source, int pageSize)
        {
            GroupListRequest request = new GroupListRequest();
            request.PageSize = pageSize;
            return new TRequestBinder<GroupReply, GetListOperation>
            (
                source, RequestBuilder.BuildGetEntityListRequest(request)
            );
        }
        public static BaseRequestBinder BuildGetGroupListRequest(BaseUserControl source, GroupListRequest request)
        {
            return new TRequestBinder<GroupReply, GetListOperation>
            (
                source, RequestBuilder.BuildGetEntityListRequest(request)
            );
        }
        public static BaseRequestBinder BuildAddGroupRequest(Group group)
        {
            return new TBaseRequestBinder<GroupReply, AddOperation>
            (
                RequestBuilder.BuildAddEntityRequest<GroupRequest>(group)
            );
        }
        public static BaseRequestBinder BuildUpdateGroupRequest(Group group)
        {
            return new TBaseRequestBinder<GroupReply, UpdateOperation>
            (
                RequestBuilder.BuildUpdateEntityRequest<GroupRequest>(group)
            );
        }
        public static BaseRequestBinder BuildDeleteGroupRequest(int groupId)
        {
            return new TBaseRequestBinder<GroupReply, DeleteOperation>
            (
                RequestBuilder.BuildDeleteEntityRequest<GroupRequest>(groupId)
            );
        }

        public static BaseRequestBinder BuildGetSectionRequest(BaseUserControl source)
        {
            return new TRequestBinder<SectionReply, GetOperation>
            (
                source, RequestBuilder.BuildGetEntityRequest<SectionRequest>()
            );
        }
        public static BaseRequestBinder BuildGetSectionRequest(int sectionId)
        {
            return new TBaseRequestBinder<SectionReply, GetOperation>
            (
                RequestBuilder.BuildGetEntityRequest<SectionRequest>(sectionId)
            );
        }
        public static BaseRequestBinder BuildGetSectionRequest(BaseUserControl source, int sectionId)
        {
            return new TRequestBinder<SectionReply, GetOperation>
            (
                source, RequestBuilder.BuildGetEntityRequest<SectionRequest>(sectionId)
            );
        }
        public static BaseRequestBinder BuildGetSectionListRequest(BaseUserControl source, int groupId)
        {
            SectionListRequest request = new SectionListRequest();
            request.GroupId = groupId;

            return new TRequestBinder<SectionReply, GetListOperation>
            (
                source, RequestBuilder.BuildGetEntityListRequest(request)
            );
        }
        public static BaseRequestBinder BuildGetSectionListRequest(BaseUserControl source, SectionListRequest request)
        {
            return new TRequestBinder<SectionReply, GetListOperation>
            (
                source, RequestBuilder.BuildGetEntityListRequest(request)
            );
        }
        public static BaseRequestBinder BuildAddSectionRequest(Section section)
        {
            return new TBaseRequestBinder<SectionReply, AddOperation>
            (
                RequestBuilder.BuildAddEntityRequest<SectionRequest>(section)
            );
        }
        public static BaseRequestBinder BuildUpdateSectionRequest(Section section)
        {
            return new TBaseRequestBinder<SectionReply, UpdateOperation>
            (
                RequestBuilder.BuildUpdateEntityRequest<SectionRequest>(section)
            );
        }
        public static BaseRequestBinder BuildDeleteSectionRequest(int sectionId)
        {
            return new TBaseRequestBinder<SectionReply, DeleteOperation>
            (
                RequestBuilder.BuildDeleteEntityRequest<SectionRequest>(sectionId)
            );
        }

        public static BaseRequestBinder BuildGetSectionRoleUserRequest(BaseUserControl source)
        {
            return new TRequestBinder<SectionRoleUserReply, GetOperation>
            (
                source, RequestBuilder.BuildGetEntityRequest<SectionRoleUserRequest>()
            );
        }
        public static BaseRequestBinder BuildGetSectionRoleUserRequest(int dataId)
        {
            return new TBaseRequestBinder<SectionRoleUserReply, GetOperation>
            (
                RequestBuilder.BuildGetEntityRequest<SectionRoleUserRequest>(dataId)
            );
        }
        public static BaseRequestBinder BuildGetSectionRoleUserRequest(BaseUserControl source, int dataId)
        {
            return new TRequestBinder<SectionRoleUserReply, GetOperation>
            (
                source, RequestBuilder.BuildGetEntityRequest<SectionRoleUserRequest>(dataId)
            );
        }
        public static BaseRequestBinder BuildGetSectionRoleUserListRequest(BaseUserControl source)
        {
            return new TRequestBinder<SectionRoleUserReply, GetListOperation>
            (
                source, RequestBuilder.BuildGetEntityListRequest<SectionRoleUserListRequest>()
            );
        }
        public static BaseRequestBinder BuildGetSectionRoleUserListRequest(BaseUserControl source, int sectionId, int roleId)
        {
            SectionRoleUserListRequest request = new SectionRoleUserListRequest();
            request.SectionId = sectionId;
            request.RoleId = roleId;

            return new TRequestBinder<SectionRoleUserReply, GetListOperation>
            (
                source, RequestBuilder.BuildGetEntityListRequest(request)
            );
        }
        public static BaseRequestBinder BuildGetSectionRoleUserListRequest(BaseUserControl source, SectionRoleUserListRequest request)
        {
            return new TRequestBinder<SectionRoleUserReply, GetListOperation>
            (
                source, RequestBuilder.BuildGetEntityListRequest(request)
            );
        }
        public static BaseRequestBinder BuildAddSectionRoleUserRequest(SectionRoleUser sectionRoleUser)
        {
            return new TBaseRequestBinder<SectionRoleUserReply, AddOperation>
            (
                RequestBuilder.BuildAddEntityRequest<SectionRoleUserRequest>(sectionRoleUser)
            );
        }
        public static BaseRequestBinder BuildUpdateSectionRoleUserRequest(SectionRoleUser sectionRoleUser)
        {
            return new TBaseRequestBinder<SectionRoleUserReply, UpdateOperation>
            (
                RequestBuilder.BuildUpdateEntityRequest<SectionRoleUserRequest>(sectionRoleUser)
            );
        }
        public static BaseRequestBinder BuildDeleteSectionRoleUserRequest(int entityId)
        {
            return new TBaseRequestBinder<SectionRoleUserReply, DeleteOperation>
            (
                RequestBuilder.BuildDeleteEntityRequest<SectionRoleUserRequest>(entityId)
            );
        }
        public static BaseRequestBinder BuildDeleteSectionRoleUserRequest(int sectionId, int roleId, int userId)
        {
            SectionRoleUserRequest request = new SectionRoleUserRequest();
            request.CommandIdent = ForumCommandIdent.DeleteSectionRoleUser;
            request.SectionId = sectionId;
            request.RoleId = roleId;
            request.UserId = userId;
            return new TBaseRequestBinder<SectionRoleUserReply, DeleteOperation>
            (
                RequestBuilder.BuildDeleteEntityRequest(request)
            );
        }

        public static BaseRequestBinder BuildGetThreadRequest()
        {
            return new TBaseRequestBinder<ThreadReply, GetOperation>
            (
                RequestBuilder.BuildGetEntityRequest<ThreadRequest>()
            );
        }
        public static BaseRequestBinder BuildGetThreadRequest(BaseUserControl source)
        {
            return new TRequestBinder<ThreadReply, GetOperation>
            (
                source, RequestBuilder.BuildGetEntityRequest<ThreadRequest>()
            );
        }
        public static BaseRequestBinder BuildGetThreadRequest(int threadId)
        {
            return new TBaseRequestBinder<ThreadReply, GetOperation>
            (
                RequestBuilder.BuildGetEntityRequest<ThreadRequest>(threadId)
            );
        }
        public static BaseRequestBinder BuildGetThreadListRequest(BaseUserControl source, int pageSize)
        {
            ThreadListRequest request = new ThreadListRequest();
            request.CommandIdent = ForumCommandIdent.GetThreads;
            request.PageSize = pageSize;

            return new TRequestBinder<ThreadReply, GetListOperation>
            (
                source, RequestBuilder.BuildGetEntityListRequest(request)
            );
        }
        public static BaseRequestBinder BuildGetThreadListRequest(BaseUserControl source, int pageSize, int orderType)
        {
            ThreadListRequest request = new ThreadListRequest();

            request.CommandIdent = ForumCommandIdent.GetThreads;
            request.PageSize = pageSize;
            request.OrderField = orderType;

            return new TRequestBinder<ThreadReply, GetListOperation>
            (
                source, RequestBuilder.BuildGetEntityListRequest(request)
            );
        }
        public static BaseRequestBinder BuildGetThreadListRequest(ThreadListRequest request, int orderType)
        {
            request.CommandIdent = ForumCommandIdent.GetThreads;
            request.OrderField = orderType;

            return new TBaseRequestBinder<ThreadReply, GetListOperation>
            (
                RequestBuilder.BuildGetEntityListRequest(request)
            );
        }
        public static BaseRequestBinder BuildGetThreadViewListRequest(ThreadListRequest request, int orderType)
        {
            request.CommandIdent = ForumCommandIdent.GetThreads;
            request.OrderField = orderType;
            request.ThreadReleaseStatus = (int)ThreadReleaseStatus.Open;

            return new TBaseRequestBinder<ThreadReply, GetListOperation>
            (
                RequestBuilder.BuildGetEntityListRequest(request)
            );
        }
        public static BaseRequestBinder BuildGetThreadListRequest(BaseUserControl source, ThreadListRequest request, int pageSize, int orderType)
        {
            request.CommandIdent = ForumCommandIdent.GetThreads;
            request.PageSize = pageSize;
            request.OrderField = orderType;

            return new TRequestBinder<ThreadReply, GetListOperation>
            (
                source, RequestBuilder.BuildGetEntityListRequest(request)
            );
        }
        public static BaseRequestBinder BuildAddThreadRequest(Thread thread)
        {
            return new TBaseRequestBinder<ThreadReply, AddOperation>
            (
                RequestBuilder.BuildAddEntityRequest<ThreadRequest>(thread)
            );
        }
        public static BaseRequestBinder BuildUpdateThreadRequest(Thread thread)
        {
            return new TBaseRequestBinder<ThreadReply, UpdateOperation>
            (
                RequestBuilder.BuildUpdateEntityRequest<ThreadRequest>(thread)
            );
        }
        public static BaseRequestBinder BuildDeleteThreadRequest(int threadId)
        {
            return new TBaseRequestBinder<ThreadReply, DeleteOperation>
            (
                RequestBuilder.BuildDeleteEntityRequest<ThreadRequest>(threadId)
            );
        }

        public static BaseRequestBinder BuildGetPostRequest(BaseUserControl source)
        {
            return new TRequestBinder<PostReply, GetOperation>
            (
                source, RequestBuilder.BuildGetEntityRequest<PostRequest>()
            );
        }
        public static BaseRequestBinder BuildGetPostRequest(int postId)
        {
            return new TBaseRequestBinder<PostReply, GetOperation>
            (
                RequestBuilder.BuildGetEntityRequest<PostRequest>(postId)
            );
        }
        public static BaseRequestBinder BuildGetPostListRequest()
        {
            PostListRequest request = new PostListRequest();
            request.OrderFields.Add(new OrderField(request.Entity, "EntityId", true));

            return new TBaseRequestBinder<PostReply, GetListOperation>
            (
                RequestBuilder.BuildGetEntityListRequest(request)
            );
        }
        public static BaseRequestBinder BuildGetPostListRequest(BaseUserControl source, int pageSize)
        {
            PostListRequest request = new PostListRequest();
            request.PageSize = pageSize;
            request.OrderFields.Add(new OrderField(request.Entity, "EntityId", true));

            return new TRequestBinder<PostReply, GetListOperation>
            (
                source, RequestBuilder.BuildGetEntityListRequest(request)
            );
        }
        public static BaseRequestBinder BuildGetPostListRequest(BaseUserControl source)
        {
            PostListRequest request = new PostListRequest();
            request.OrderFields.Add(new OrderField(request.Entity, "EntityId", true));

            return new TRequestBinder<PostReply, GetListOperation>
            (
                source, RequestBuilder.BuildGetEntityListRequest(request)
            );
        }
        public static BaseRequestBinder BuildAddPostRequest(Post post)
        {
            return new TBaseRequestBinder<PostReply, AddOperation>
            (
                RequestBuilder.BuildAddEntityRequest<PostRequest>(post)
            );
        }
        public static BaseRequestBinder BuildUpdatePostRequest(Post post)
        {
            return new TBaseRequestBinder<PostReply, UpdateOperation>
            (
                RequestBuilder.BuildUpdateEntityRequest<PostRequest>(post)
            );
        }
        public static BaseRequestBinder BuildDeletePostRequest(int postId)
        {
            return new TBaseRequestBinder<PostReply, DeleteOperation>
            (
                RequestBuilder.BuildDeleteEntityRequest<PostRequest>(postId)
            );
        }
    }
}